import json
import random
import string

import requests

from faker import Faker

def generate_phone_numbers(count):
    phone_numbers = set()
    while len(phone_numbers) < count:
        # 生成随机的电话号码
        phone_number = "1" + "".join(random.choices(string.digits, k=10))
        phone_numbers.add(phone_number)
    return phone_numbers

# 生成100个不重复的电话号码
phone_numbers = generate_phone_numbers(150)
for itemId in phone_numbers:  #
    lastItem = itemId
    urlSave = 'http://127.0.0.1:8081/api/front/login/mobile'
    # headers = {'Authorization': PEXELS_API_KEY}
    headers = {
        'User-Agent': 'Mozilla/5.0 (X11; Linux aarch64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.188 Safari/537.36 CrKey/1.54.250320',
        # 'Authori-Zation': 'd8bed6776ecb49fdb6a734c5cc86653e',
        'Content-Type': 'application/json'
    }
    #       评分数据
    jsonComment = '{"captcha": "123456","phone": "123456","spread_spid": 0}'
    productComment = json.loads(jsonComment)
    productComment['phone'] = itemId
    productComment = json.dumps(productComment)
    # 插入item评分*******************
    response = requests.post(urlSave, data=productComment, headers=headers)
    if response.status_code == 200:
        data = response.json()
        # print(data)
        if data['code'] == 200:
            print(f"插入{itemId}成功")
        else:
            print(f"插入{itemId}评论失败,code!=200")
    else:
        print(f"插入{itemId}评论失败,无响应")
    # 评分*******************



print('++++++++++++++++++++++++++++++++')
re={
    '插入到postId,':lastItem
}
# 数据库出错了，
with open('./re/insetResult_Comment' + str(1) + '.json', 'w', encoding='utf-8') as f:
    json.dump(re, f, ensure_ascii=False, indent=4)
